package io.github.talelin.latticy.service.impl.ag;

import io.github.talelin.latticy.dto.ag.MonitoringObject.CreateOrUpdateMonitoringObjectDTO;
import io.github.talelin.latticy.mapper.ag.MonitoringObjectMapper;
import io.github.talelin.latticy.model.ag.MonitoringObejctDO;
import io.github.talelin.latticy.service.ag.MonitoringObjectService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class MonitoringObjectServiceImpl implements MonitoringObjectService {

    @Autowired
    MonitoringObjectMapper mapper;

    @Override
    public MonitoringObejctDO getById(int id) {
        return mapper.selectById(id);
    }

    @Override
    public List<MonitoringObejctDO> getMonitoringObejcts() {
        return mapper.selectList(null);
    }


    @Override
    public boolean createRoom(CreateOrUpdateMonitoringObjectDTO validator) {
        MonitoringObejctDO Mo = new MonitoringObejctDO();
        Mo.setUnitId(validator.getUnit_id());
        Mo.setMoId(validator.getMo_id());
        Mo.setMoType(validator.getMo_type());
        Mo.setMoState(validator.getMo_state());
        return mapper.insert(Mo) > 0;
    }

    @Override
    public boolean deleteById(int id) {
        return mapper.deleteById(id)>0;
    }

    @Override
    public boolean updateMonitoringObject(MonitoringObejctDO monitoringObj, CreateOrUpdateMonitoringObjectDTO validator) {
        monitoringObj.setUnitId(validator.getUnit_id());
        monitoringObj.setMoType(validator.getMo_type());
        monitoringObj.setMoState(validator.getMo_state());

        return mapper.updateById(monitoringObj) > 0;
    }
}
